package dangan;

import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import java.util.Scanner;
import util.JDBCUtils;

import org.junit.jupiter.api.Test;

import dangan.bean.StudentBean;
import dangan.danganDao.StudentDao;

public class danganguan {
	
	
	public static void main(String[] args) throws ClassNotFoundException, IOException {
		while (true) {
			System.out.println("1.录入学生信息");
			System.out.println("2.查看学生信息");
			System.out.println("3.按学生姓名查询学生信息");
			System.out.println("4.按专业查询学生信息");
			System.out.println("请输入要进行的操作");
			danganguan d = new danganguan();
			d.caozuo();
		}
	}

	public void caozuo() throws ClassNotFoundException, IOException {
		Scanner scanner = new Scanner(System.in);
		String xuanze = scanner.nextLine();

		switch (xuanze) {
		case "1":
			insert();
			break;
		case "2":
			selectAll();
			break;
		case "3":
			selectByName();
			break;
		case "4":
			selectByZhuan();
			break;
		default:
			break;
		}
	}
	
	@Test
	public void selectByZhuan() {
		System.out.println("请输入学生专业：");
		String zhuanye=input();
		
		StudentBean stu=new StudentBean();
		stu.setZhuanye(zhuanye);
		
		StudentDao dao=new StudentDao();
		List<StudentBean> list=dao.selectByZhuan(stu);
		System.out.println(list);
		
		
	}

	public String input() {
		Scanner sc=new Scanner(System.in);
		return sc.nextLine();
	}
	
	@Test
	public void selectByName() {
		System.out.println("请输入学生姓名：");
		String name=input();
		StudentBean stu=new StudentBean();
		stu.setName(name);
		
		StudentDao dao=new StudentDao();
		List<StudentBean> list=dao.selectByName(stu);
		System.out.println(list);
	}

	@Test
	public void selectAll() {
		System.out.println("学生全部信息：");
		StudentDao dao =new StudentDao();
		List<StudentBean> list = dao.selectAll();
		System.out.println(list);
		
	}

	@Test
	public void insert() throws ClassNotFoundException, IOException {
		StudentDao dao=new StudentDao();
		
		StudentBean stu = new StudentBean();
		Scanner sc = new Scanner(System.in);
		System.out.println("请输入学生id号");
		int id = Integer.parseInt(sc.nextLine());
		System.out.println("请输入学生姓名");
		String name = sc.nextLine();
		System.out.println("请输入学生专业");
		String zhuanye = sc.nextLine();
		System.out.println("请输入学生性别");
		int sex = 0;
		String xingbie = sc.nextLine();
		if (xingbie.equals("男")) {
			sex = 0;
		} else {
			sex = 1;
		}
		
		stu.setId(id);
		stu.setName(name);
		stu.setZhuanye(zhuanye);
		stu.setSex(sex);
		try {
			dao.insert(stu);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

}
